#include<vector>
#include<iostream>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;

namespace leetcode{
    class solution_396_zkm{
    /*
    @url:    https://leetcode-cn.com/problems/rotate-function/
    @method: dfs
    */
    public:
        solution_396_zkm(){
            vector<int>nums;
            get_data(nums);
            cout<<maxRotateFunction(nums)<<endl;
        }

        void get_data(vector<int>& data){
            data = {-1,0,0,1,1,2};
        }
        void get_data(vector<int>& data){
            data = {4,3,2,6};
        }


        int maxRotateFunction(vector<int>& nums) {
            int sz = nums.size();
            int sums = nums[0];int val = 0;
            for(int i=1;i<sz;++i){
                sums += nums[i];
                val += i * nums[i];
            }
            int res = val;
            for(int i=1;i<sz;++i){
                val += sz*(nums[i-1]) - sums;
                res = max(res,val);
            }
            return res;
        }
    };
}